/*
 * Copyright (c) 2001-2018 GuaHao.com Corporation Limited. All rights reserved.
 * This software is the confidential and proprietary information of GuaHao Company.
 * ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with GuaHao.com.
 */
package com.bgt.springboot.first.utils;

import org.apache.commons.lang.StringUtils;

/**
 * TODO
 *
 * @author Ricky
 * @version V1.0
 * @since 2018-08-14 15:27
 */
public class TestInteger {

    public static Integer getFenInt4YuanStr(String moneyStr) {
        String reg = "^\\d{1,7}(\\.\\d{0,5})?$";
        if (StringUtils.isNotBlank(moneyStr) && moneyStr.matches(reg)) {
            String[] split = moneyStr.split("\\.");
            Integer fenPart = 0;
            if (split.length > 1) {
                if (split[1].length() == 1) {// 如果是1位小数
                    fenPart = Integer.valueOf(split[1]) * 10;
                } else if (split[1].length() > 1) {
                    // 只取两位小数
                    fenPart = Integer.valueOf(split[1].substring(0, 2));
                }
            }
            return Integer.valueOf(split[0]) * 100 + fenPart;
        } else {
            return null;
        }
    }

    public static void main(String[] args) {
        System.out.println(getFenInt4YuanStr("10.0123"));
    }
}
